package com.xinxin.leetcode.problem415;

import java.math.BigInteger;

/**
 * @author ShiXinXin
 * @date 2019-12-16 11:16
 */
public class Solution {
    public String addStrings(String num1, String num2) {
        StringBuilder sb = new StringBuilder();
        int carry = 0, i = num1.length() - 1, j = num2.length() - 1;
        while (i >= 0 || j >= 0 || carry != 0) {
            if (i >= 0) {
                carry += num1.charAt(i--) - '0';
            }
            if (j >= 0) {
                carry += num2.charAt(j--) - '0';
            }
            sb.insert(0, (carry % 10));
            carry /= 10;
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution().addStrings("123", "456"));
        BigInteger num=new BigInteger("-0");
        BigInteger num2=new BigInteger("-0");
        BigInteger res = num.add(num2);
        System.out.println(res);
    }
}
